package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.monitor.entity.ErpContractIntegral;
import com.monitor.service.ErpContractIntegralService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 合同协议积分使用表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-17
 */
@RestController
@RequestMapping("/erpContractIntegral")
@Api(description="合同协议-积分消费")
public class ErpContractIntegralController {

    @Resource
    private ErpContractIntegralService integralService;

    @RequestMapping("/inertOrUpdateIntegral")
    @ApiOperation("添加Or修改积分消费信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> inertOrUpdateIntegral(ErpContractIntegral contract) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(integralService.insertOrUpdate(contract)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getIntegraltById")
    @ApiOperation("根据积分消费id积分消费信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "contractId", value = "积分消费ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpContractIntegral> getIntegraltById(Integer contractId) {
        Result<ErpContractIntegral> result=new Result<ErpContractIntegral>();
        try{
            result.setCount(1);
            result.setData(integralService.selectById(contractId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getIntegraltByConId")
    @ApiOperation("根据协议id积分消费信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "conId", value = "协议ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpContractIntegral>> getIntegraltByConId(Integer contractId) {
        Result<List<ErpContractIntegral>> result=new  Result<List<ErpContractIntegral>> ();
        try{
            result.setCount(1);
            result.setData(integralService.selectList(new EntityWrapper<ErpContractIntegral>().eq("contract_id",contractId)));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getIntegralById")
    @ApiOperation("根据积分消费id积分消费信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "contractId", value = "积分消费ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpContractIntegral> getIntegralById(Integer contractId) {
        Result<ErpContractIntegral> result=new Result<ErpContractIntegral>();
        try{
            result.setCount(1);
            result.setData(integralService.selectById(contractId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removetIntegralById")
    @ApiOperation("根据积分消费id删除积分消费信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "contractId", value = "积分消费ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removetIntegralById(Integer id) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(integralService.deleteById(id)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }



}

